﻿using Microsoft.EntityFrameworkCore;
using Prism.Ioc;
using Prism.Regions;
using Prism.Unity;
using SmartParking.Base;
using SmartParking.IService;
using SmartParking.ORM;
using SmartParking.Service;
using SmartParking.View;
using SmartParking.ViewModels;
using System.Configuration;
using System.Data;
using System.Windows;

namespace SmartParking
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<MainView>();
        }

        protected override void InitializeShell(Window shell)
        {
            base.InitializeShell(shell);

            Container.Resolve<IRegionManager>().RegisterViewWithRegion("MainRegion", "DashboardView");
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterForNavigation<MainView, MainViewModel>();
            
            containerRegistry.RegisterDialogWindow<DialogWindowEx>();


            //注册实体类

            /// 单例模式注册数据库上下文，消除EFCore缓存。
            containerRegistry.RegisterSingleton<DbContext, ORM.SmartParkingMySqlEntity.SmartParkingContext>();

            containerRegistry.RegisterDialog<LoginView, LoginViewModel>();
            
            containerRegistry.Register<IUserService, UserService>();
            containerRegistry.Register<IMenuService, MenuService>();

            containerRegistry.RegisterForNavigation<Views.Pages.DashboardView, ViewModels.Pages.DashboardViewModel>();
            containerRegistry.RegisterForNavigation<Views.Pages.UserManagementView, ViewModels.Pages.UserManagementViewModel>();
            containerRegistry.RegisterForNavigation<Views.Pages.RoleManagementView, ViewModels.Pages.RoleManagementViewModel>();
            containerRegistry.RegisterForNavigation<Views.Pages.MenuManagementView, ViewModels.Pages.MenuManagementViewModel>();

            containerRegistry.RegisterDialog<Views.Pages.Dialogs.ModifyMenuView, ViewModels.Pages.Dialogs.ModifyMenuViewModel>();
            containerRegistry.RegisterDialog<Views.Pages.Dialogs.ModifyUserView, ViewModels.Pages.Dialogs.ModifyUserViewModel>();
        }

    }

}
